﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMeterParamFrame.Model.DIValueConverters
{

    /// <summary>
    /// 日期及周期 ，转换类
    /// </summary>
    class Converter_Date : IDIDataConverter
    {
        public bool CanConverter(string di)
        {
            return di.Equals("04000101");
        }

        public string ConvertToUI(string di, string value)
        {
            if (value.Length != 8)
            {
                throw new ArgumentException();
            }

            string newValue = value.Substring(0, 2) + "-" +
                value.Substring(2, 2) + "-" +
                value.Substring(4, 2) + " " +
                value.Substring(6, 2);
            return newValue;
        }

        public string ConvertToLow(string di, string value)
        {
            string[] values = value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            if (values.Length != 2)
            {
                throw new ArgumentException();
            }

            string[] dates = values[0].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            dates[1] = dates[1].PadLeft(2, '0');
            dates[2] = dates[2].PadLeft(2, '0');
            values[0] = dates[0] + dates[1] + dates[2];
            values[1] = values[1].PadLeft(2, '0');
            string newValue = values[0] + values[1];
            return newValue;
        }

        public bool ValidateValue(string di, string value)
        {
            throw new NotImplementedException();
        }
    }
}
